package cn.db101.api.complex.component

import cn.db101.api.complex.api.weather.gaode.GaoDeFutureResponse
import cn.db101.api.complex.api.weather.xinzhi.CurrentResponse
import cn.db101.api.complex.api.weather.xinzhi.FutureResponse
import cn.db101.api.complex.model.response.WeatherCurrentResponse
import cn.db101.api.complex.model.response.WeatherFutureResponse
import org.mapstruct.Mapper
import org.mapstruct.Mapping
import org.mapstruct.Mappings
import org.mapstruct.Named
import org.mapstruct.factory.Mappers

/**
 * @author zooy
 * @since 2024/11/11-15:37
 */
@Mapper
interface WeatherMapper {

    companion object {
        val INSTANCE: WeatherMapper = Mappers.getMapper(WeatherMapper::class.java)
    }

    @Mappings(
        Mapping(source = "text", target = "result.textWeather"),
        Mapping(source = "temperature", target = "result.temperature"),
        Mapping(source = "windDirection", target = "result.windDirection"),
        Mapping(source = "windScale", target = "result.windScale"),
        Mapping(source = "humidity", target = "result.humidity"),
        Mapping(target = "city", ignore = true)
    )
    fun xinZhiCurrentConvert(futureResponseResult: CurrentResponse.Now?): WeatherCurrentResponse

    @Mappings(
        Mapping(source = "location.name", target = "city"),
        Mapping(source = "daily", target = "result", qualifiedByName = arrayOf("xinZhiDailyConvert"))
    )
    fun xinZhiFutureConvert(futureResponseResult: FutureResponse.Result?): WeatherFutureResponse

    @Mappings(
        Mapping(source = "high", target = "highTemperature"),
        Mapping(source = "low", target = "lowTemperature")
    )
    @Named("xinZhiDailyConvert")
    fun xinZhiDailyConvert(daily: FutureResponse.Daily?): WeatherFutureResponse.Result

    @Mappings(
        Mapping(source = "weather", target = "result.textWeather"),
        Mapping(source = "temperature", target = "result.temperature"),
        Mapping(source = "winddirection", target = "result.windDirection"),
        Mapping(source = "windpower", target = "result.windScale"),
        Mapping(source = "humidity", target = "result.humidity")
    )
    fun gaoDeCurrentConvert(live: GaoDeFutureResponse.Live?): WeatherCurrentResponse

    @Mappings(
        Mapping(source = "casts", target = "result", qualifiedByName = arrayOf("gaoDeCastConvert")),
    )
    fun gaoDeFutureConvert(forecast: GaoDeFutureResponse.Forecast?): WeatherFutureResponse

    @Mappings(
        Mapping(source = "date", target = "date"),
        Mapping(source = "dayweather", target = "textDay"),
        Mapping(source = "nightweather", target = "textNight"),
        Mapping(source = "daytemp", target = "highTemperature"),
        Mapping(source = "nighttemp", target = "lowTemperature"),
        Mapping(target = "windDirection", ignore = true),
        Mapping(target = "windScale", ignore = true),
        Mapping(target = "humidity", ignore = true)
    )
    @Named("gaoDeCastConvert")
    fun gaoDeCastConvert(cast: GaoDeFutureResponse.Cast?): WeatherFutureResponse.Result

}
